package com.huanong.controller.impl;
/*
 *@Author:anran
 *@Date:2020/12/9
 *@Version 1.0
 */

import com.huanong.common.grace.result.GraceJSONResult;
import com.huanong.controller.OrderControllerApi;
import com.huanong.pojo.Order;
import com.huanong.pojo.vo.OrderVo;
import com.huanong.service.OrderService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderController implements OrderControllerApi {

    @Autowired
    private OrderService orderService;

    @Override
    public GraceJSONResult query() {
        List<Order> list=orderService.query();
        return GraceJSONResult.ok(list);
    }

    @Override
    public GraceJSONResult queryOrderById(Integer OsId) {
        Order order=orderService.queryById(OsId);
        return GraceJSONResult.ok(order);
    }

    @Override
    public GraceJSONResult orderQueryByUserid(Integer psId) {
        List<Order> orders = orderService.queryByUserid(psId);
        return GraceJSONResult.ok(orders);
    }

    @Override
    public GraceJSONResult addOrder(OrderVo order) {
        int flag=orderService.add(order);
        if (flag==1){
            return GraceJSONResult.ok("增加订单信息成功");
        }else {
            return GraceJSONResult.errorMsg("增加订单信息失败");
        }
    }

    @Override
    public GraceJSONResult deleteOrder(Integer OsId) {
        int flag=orderService.delete(OsId);
        if (flag==1){
            return GraceJSONResult.ok("删除订单信息成功");
        }else if (flag==0){
                return GraceJSONResult.ok("没有订单信息");
        }else {
            return GraceJSONResult.errorMsg("删除订单信息失败");
        }
    }

    @Override
    public GraceJSONResult updataStatusOrder(OrderVo order) {
        if (order == null || order.getOsId() == null || order.getOsStatus() == null || order.getOsStatus() == -1) {
            return GraceJSONResult.errorMsg("请求参数错误");
        }

        orderService.updataStatus(order);
        return GraceJSONResult.ok();
    }
}
